package com.sanley.piss.web.controller;

import com.sanley.piss.web.service.mapper.IUserService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;


/**
 * @author limk
 * @date 2020/12/24 21:14
 */
@ApiIgnore
@RestController
@RequestMapping("/")
public class TestController {
    @Autowired
    private IUserService service;

    /**
     * 测试拥有某个角色
     */
    @GetMapping("/test")
    @RequiresRoles(value = {"admin", "test"}, logical = Logical.OR)
    public String test1() {
        return "test";
    }

    /**
     * 测试拥有某个权限
     */
    @GetMapping("/get/user")
    @RequiresPermissions(value = {"user:get", "user:list"}, logical = Logical.AND) // and 同时满足；or 任意满足一个
    public String test2() {
        return "test";
    }

    @GetMapping("/")
    public String redirect() {
        return "redirect";
    }

    @GetMapping("/index")
    public String index() {
        return "success";
    }

    @GetMapping("/401")
    public String unauthorized() {
        return "unauthorized";
    }

    @GetMapping("/403")
    public String forbidden() {
        return "forbidden";
    }

    @GetMapping("/failure")
    public String failure() {
        return "failure";
    }

    @GetMapping("/success")
    public String success() {
        return "success";
    }


    @GetMapping("/testtest")
    public String testest(){
        return "ok";
    }

}
